//
//  VisitorView.swift
//  WeiBo001
//
//  Created by ZhiQiang Li on 16/7/20.
//  Copyright © 2016年 ZhiQiang Li. All rights reserved.
//

import UIKit
import SnapKit
class VisitorView: UIView {
    //声明一个闭包
    var closure:(()->())?
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //监听方法
@objc   private func loginBtnClick(){
 closure?()
    
    }
    //供外界调用
    func setupVisitorViewInfo(imgName: String?,title: String?){
        if let img = imgName, let tit = title{
            iconImgView.image = UIImage(named: img)
            messageLabel.text = tit
            feedImgView.hidden = true
            

            
        }else{
            //首页
        }
    }
    //设置动画
    
    func setupAnim(){
        let anim = CABasicAnimation(keyPath: "transform.rotation")
        anim.toValue =  M_PI * 2
        anim.duration = 10
        anim.repeatCount = MAXFLOAT
        anim.removedOnCompletion = false
        //添加动画
        feedImgView.layer.addAnimation(anim, forKey: nil)
        
    }
    //设置视图
    func  setupUI(){
       backgroundColor = RGB(237, green: 237, blue: 237)
        //添加控件
        addSubview(feedImgView)
        addSubview(keepImgView)
        addSubview(iconImgView)
        addSubview(messageLabel)
        addSubview(loginBtn)
        addSubview(regBtn)
        //添加约束
        feedImgView.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(self)
        }
        keepImgView.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(self)
        }
        iconImgView.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(self)
        }
        messageLabel.snp_makeConstraints { (make) -> Void in
            make.width.equalTo(230)
            make.height.equalTo(38)
            make.top.equalTo(keepImgView.snp_bottom).offset(18)
            make.centerX.equalTo(self)
        }
        loginBtn.snp_makeConstraints { (make) -> Void in
            make.width.equalTo(80)
            make.height.equalTo(30)
            make.top.equalTo(messageLabel.snp_bottom).offset(18)
            make.leading.equalTo(messageLabel)
        }
        regBtn.snp_makeConstraints { (make) -> Void in
            make.width.equalTo(80)
            make.height.equalTo(30)
            make.top.equalTo(messageLabel.snp_bottom).offset(18)
            make.trailing.equalTo(messageLabel)
 
        }
        
    }
    
    //懒加载控件
    //转圈
    private lazy var feedImgView:UIImageView = UIImageView(imageName:"visitordiscover_feed_image_smallicon")
    
    //遮挡图片
     private lazy var keepImgView: UIImageView = UIImageView(imageName: "visitordiscover_feed_mask_smallicon")
    // 房子图片
    private lazy var iconImgView: UIImageView =  UIImageView(imageName: "visitordiscover_feed_image_house")
    // 文字
    private lazy var messageLabel:UILabel = {
        let lab = UILabel(textColor: UIColor.grayColor(), textFont: 15)
        lab.text = "关注一些人，回这里看看有什么惊喜"
        lab.numberOfLines = 0
        lab.textAlignment = .Center
        return lab
    }()
    //登录按钮
    private lazy var loginBtn: UIButton = {
        let button = UIButton()
        
        button.addTarget(self, action: "loginBtnClick", forControlEvents: UIControlEvents.TouchUpInside)
        button.setTitle("登录", forState: UIControlState.Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(14)
        button.setTitleColor(ThemeColor, forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        return button
    }()
    
    //注册按钮
    private lazy var regBtn: UIButton = {
        let button = UIButton()
        // 添加点击时间
        button.addTarget(self, action: "loginBtnClick", forControlEvents: UIControlEvents.TouchUpInside)
        button.setTitle("注册", forState: UIControlState.Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(14)
        button.setTitleColor(ThemeColor, forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        return button
    }()

    
    
}


